package com.jason.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitConfig {

    @Bean
    public Queue payQueue() {
        Map<String, Object> arguments = new HashMap<>();
        //过期时间 3分钟
        arguments.put("x-message-ttl", 1000 * 60 * 1);
        //死信队列可交换器
        arguments.put("x-dead-letter-exchange", "ex.dead.pay");
        //死信交换器routingKey
        arguments.put("x-dead-letter-routing-key", "dead.pay");
        return new Queue("pay.queue", false, false, false, arguments);
    }

    @Bean
    public Exchange exchange() {
        return new DirectExchange("ex.pay", false, false);
    }

    @Bean
    public Exchange exchange1() {
        return new DirectExchange("ex.dead.pay", false, false);
    }

    @Bean
    public Binding binding() {
        return new Binding("pay.queue", Binding.DestinationType.QUEUE, "ex.pay", "rout.pay", null);
    }

    @Bean
    public Binding binding1() {
        return new Binding("dead.pay", Binding.DestinationType.QUEUE, "ex.dead.pay", "dead.pay", null);
    }

    @Bean
    public Queue deadPayQueue() {
        return new Queue("dead.pay", false, false, false);
    }

}
